package com.zhongxi.guoyuan.adapter.rewardCoin;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.application.MyApplication;
import com.zhongxi.guoyuan.entity.rewardcoin.GoodListInfo;
import com.zhongxi.guoyuan.url.Url;
import com.zhongxi.guoyuan.utils.DataUtil;

import java.math.BigDecimal;
import java.util.List;

import static com.zhongxi.guoyuan.R.id.tv_reward_price;

/**
 * Created by Administrator on 2017/8/19.
 */

public class RewardGoodListAdapter extends BaseAdapter {
    private List<GoodListInfo> data;
    private Context context;

    public RewardGoodListAdapter(Context context, List<GoodListInfo> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        if (data != null && data.size() > 0) {
            return data.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder vh = null;
        if (view == null) {
            view = View.inflate(context, R.layout.item_reward_good, null);
            vh = new ViewHolder();
            vh.ivImg = (ImageView) view.findViewById(R.id.ivImg);
            vh.tvName = (TextView) view.findViewById(R.id.tvName);
            vh.tv_reward_price = (TextView) view.findViewById(tv_reward_price);
            vh.tv_reward_yield = (TextView) view.findViewById(R.id.tv_reward_yield);
            vh.tv_reward_coin = (TextView) view.findViewById(R.id.tv_reward_coin);
            vh.tv_viewnum = (TextView) view.findViewById(R.id.tv_viewnum);
            view.setTag(vh);
        } else {
            vh = (ViewHolder) view.getTag();
        }
        GoodListInfo goodListInfo = data.get(i);
        Glide.with(context).load(Url.IMG_URL + goodListInfo.getThumbnail()).placeholder(R.mipmap.iv_eg).into(vh.ivImg);
        if (goodListInfo.getName()!=null&&!"".equals(goodListInfo.getName())) {
            vh.tvName.setText(goodListInfo.getName());
        }else {
            vh.tvName.setText("");
        }

        if (goodListInfo.getViewnum()!=null&&!"".equals(goodListInfo.getViewnum())) {
            vh.tv_viewnum.setText(goodListInfo.getViewnum());
        }else {
            vh.tv_viewnum.setText("");
        }
        return view;
    }

    private class ViewHolder {
        private ImageView ivImg;
        private TextView tvName;
        private TextView tv_reward_price;
        private TextView tv_reward_yield;
        private TextView tv_reward_coin;
        private TextView tv_viewnum;
    }
}
